{$mode delphi}
{$define cli}
{$define distrib}
// Usage, license, and other information messages for SES
UNIT sesMessages;

INTERFACE

USES sesTypes;

// show version, options, info, usage, etc
// according to cli switches
PROCEDURE showMessages;
PROCEDURE showTitle;
PROCEDURE showInfo;
PROCEDURE showLegend;
PROCEDURE showOptions;
PROCEDURE showHelp;
PROCEDURE showChallenge;
// Error reports
PROCEDURE doError(m: TMCipher; t: SESTRING);
// GPL Terms & Conditions
PROCEDURE showShortLicense;
PROCEDURE showWarranty;
PROCEDURE showConditions;
// thanks and acknowledgments
PROCEDURE showThanks;
PROCEDURE showMagic;


IMPLEMENTATION

USES Classes, MyStrUtils, Print, sesVer, sesParams, sesCiphers;

CONST MAGIC = 'MOD 26';

PROCEDURE showTitle;
BEGIN
	Writeln(BANNER1);
END;


PROCEDURE showLegend;
	BEGIN
		Writeln;
		Writeln('SES abbreviations legend:');
		Writeln;
		Writeln('   SE: Seed');
		Writeln('   DE: Depth');
		Writeln('   PT: Plaintext');
		Writeln('   PP: Processed Plaintext');
		Writeln('   EK: Encrypted & Extended Key');
		Writeln('   VE: Vigenere Encipher');
		Writeln('   SC: Scrambled Ciphertext');
		Writeln('   KH: Keyphrase Hash');
		Writeln('   MH: Message Hash');
		Writeln('   NH: Nonce Hash');
		Writeln('   CH: Ciphertext Hash');
		Writeln('   BH: Befuddled Hash');
		Writeln('   EH: Encrypted Hash');
		Writeln('   SH: Scrambled Hash');
		Writeln('   CT: Full Ciphertext');
		Writeln('   UC: Unscrambled Ciphertext');
		Writeln('   VD: Vigenere Decipher');
		Writeln('  ISC: ISAAC Stream Cipher');
		Writeln;
	END;

	
	PROCEDURE showThanks;
	BEGIN
		Writeln;
		PrintLn('SES would not be as secure as it is without its two foundations:');
		Writeln;
		PrintLn('1) Bob Jenkins'' unassailed CSPRNG ISAAC. Bob''s ISAAC page is at http://burtleburtle.net/bob/rand/isaacafa.html');
		Writeln;
		PrintLn('2) The Keccak sponge function family, AKA SHA-3 - a new standard for cryptographic hash algorithms, as realized by Guido Bertoni, Joan Daemen, Michael Peeters and Gilles Van Assche - http://keccak.noekeon.org/');
		Writeln;
		PrintLn('SES might never have incorporated Keccak code were it not for Wolfgang Ehrhardt''s comprehensive preliminary port of it to the Pascal/Delphi platform. Wolfgang''s trove of free utilities is at http://www.wolfgang-ehrhardt.de/');
		Writeln;
		PrintLn('My thanks and appreciation to all involved in these significant endeavors.');
		Writeln;
	END;
	
	
PROCEDURE showInfo;
	VAR spl: INTEGER;
BEGIN
	Writeln;
	PrintLn('SES brings back the uncrackable onetime pad, with a digital twist. The Vigenere square combined with a random letter key of message-length is the only cipher type which is provably unbreakable.'); 
	Writeln;
	PrintLn('For total one-on-one privacy, SES traverses several levels en route to its output. The more words in your keyphrase, the more layers of encipherment SES applies. It is part Vigenere, part onetime pad, part cryptographic hash.');
	Writeln;
	spl := PrintL('SES is a symmetric-key encryption system. It uses the same secret key to encode and decode a message. To send a secret message, just paste the ciphertext generated by SES into an e-mail.');
	PrintLp(' To receive one, simply run the ciphertext through SES with the -d option. Both sender and recipient must know the key.', spl);
	Writeln;
	Write('[ MORE... ENTER ]'); Readln;
	Writeln;
	spl := PrintL('A Keccak (SHA-3) ciphertext-hash brings both avalanche and diffusion: even the tiniest change to a message will result in a completely different ciphertext. ');
	PrintLp('A unique nonce IV ensures that EVERY ciphertext is different, even the same message encrypted with the same key.', spl);
	Writeln;
	PrintLn('Along with an OTP-enciphered shell protecting the core encryption, SES makes at least five super-encipherments on any plaintext. SES is impregnable given a key-phrase of sufficient entropy. 7 years and it hasn''t been broken.');
	Writeln;
	PrintLn('Please invoke ''ses -h'' for command line options, and see the ReadMe included');
	PrintLn('with the package for more background and usage tips.');
	Writeln;
	PrintLn('As a quick-start, type ''ses -e'' at the prompt to encipher interactively.');
	Writeln;
	Write('[ END... ENTER ]'); Readln;
	Writeln;
END;


PROCEDURE showOptions;
VAR k : SESTRING = 'secret key';
	m : SESTRING = 'quick brown fox';
	c : SESTRING = '';
BEGIN
	c := sesEncipher(k,m);
	Writeln('');
	Writeln('SES <options>. {} denotes an optional element. ');
	Writeln('');
	Writeln('-a Authentication (simple): ciphertext is checked against an auth-code.');
	Writeln('-d Decipher { + ciphertext in double quotes }.');
	Writeln('-D Securely delete file or OTP after encryption { + number of passes }.'); 
	Writeln('-e Encipher { + plaintext in double quotes. }');
	Writeln('-f File to ISC-cipher byte by byte. Files of any type (up to 4GB).');
	Writeln('-F Text File to SES-cipher line by line. Slow but very secure.');
	Writeln('-g Groups. Default 4 letters. { + number after -g }.');
	Writeln('-H { Ciphertext input and output as a string of hexadecimal digits }.');
	Writeln('-k Key-phrase, quoted. Number of words dictates number of encipherments.');
	Writeln('-m Modulo of ASCII set. { + 1 (=26), 2 (=95), 3 (=128), 4 (=256) }.');
	Writeln('-o Filename of a true one-time pad from a source such as Random.org.');
	Writeln('-v Verbose. Show output from each stage of the encryption or decryption.');
	Writeln;
	Writeln('-A Special acknowledgments.');
	Writeln('-c The current SES Challenge.');
	Writeln('-h This options screen.');
	Writeln('-L Log-abbreviations legend.');
	Writeln('-t Timer operations in -v mode.');
	Writeln('-V Display SES version.');
	Writeln('');
	Writeln('Example: > ses -e "', m,'" -k "', k,'"');
	Writeln('(encrypt "', m,'" on key "', k,'")');
	Writeln('Output:  > ', c);
	Writeln('');
	Writeln('In the absence of a quoted key and message, SES becomes interactive.');
	Writeln;
END;


PROCEDURE showChallenge;
BEGIN
	Writeln;
	PrintLn('1) 1st prize: $1000 and a 1961 Cadillac Eldorado Biarritz (VGC, 3 careful owners), to the first person to conduct a successful attack on the following SES multi-level, multi-keyword encryption:');
	Writeln;
	Writeln('LSNZQSHQGJMDBDSKKPSROPSCMCHFFWHMSFOPWBLNOSBEUCQKFHLKCOPTARTPZYTYEDULNLUXI');
	Writeln;
	PrintLn('2) 2nd prize: $500 and a third edition copy of Francis Bacon''s "De Dignitate et Augmentis Scientiarum", to the first person to conduct a successful attack on the following trivial SES single-level, single keyword encryption:');
	Writeln;
	Writeln('WSXULNWLAWDUFPXSEKTKXOISHQNUZARCPPTXRDBTDRTFCJM');
	Writeln;
	PrintLn('3) 3rd prize: $100 and a set of steak-knives to be awarded for solving this short no-brainer in a familiar natural language:');
	Writeln;	
	Writeln('KMHWURXAGHOSGYZOGQSGWTIQRASGEKKAOLHAJFSSZVJPUSUOKPMSCVXHGTVSXJMXFCHTF');
	Writeln;
	PrintLn('Please email the CIPHERTEXT and PLAINTEXT to cckayne@gmail.com, detailing if possible the algorithm(s), program(s) or hardware used in your decryption, giving "SES '+VERSION+ ' Challenge" as your email''s subject. ');
	Writeln;
	Write('[ MORE... ENTER ]'); Readln;
	Writeln;
	PrintLn('Upon adjudication, funds will be transferred via PayPal to the return address on your email. No other payment options shall be considered. "Extras" to be conveyed by private arrangement.');
	Writeln;
	PrintLn('THIS CHALLENGE IS OFFERED SOLELY IN THE INTERESTS OF ENHANCING SES SECURITY AND SUPERSEDES ALL PREVIOUS CHALLENGES. IT IS IN TURN SUPERSEDED IF A NEWER MAJOR VERSION OF THE PROGRAM HAS BEEN RELEASED. BUILD NUMBERS ARE NOT TAKEN INTO CONSIDERATION.');
	Writeln;
	PrintLn('Please see the file Challenge.txt for further details and background. As of '+BUILD+', no correct solutions for any versions have been submitted.');
	Writeln;
END;


PROCEDURE doError(m: TMCipher; t: SESTRING);
	VAR es: SESTRING = 'If this error occurs repeatedly, please consider submitting a circumstantial description to the developer. This would aid greatly in improving the stability of future versions of ';
	BEGIN
		Writeln;
		doBanner;
		CASE m OF
			mEncipher:
				PrintLn('Error while enciphering "'+t+'". Perhaps you inserted a ciphertext for plaintext. '+ es+ PNAME+ '.');
			mDecipher:
				PrintLn('Error while deciphering "'+t+'". Perhaps you inserted a plaintext for ciphertext. '+ es+ PNAME+ '.');
			mNone:
				PrintLn('Unknown error while in mode "None". '+ es+ PNAME+ '.');
		ELSE
				PrintLn('Unknown error while in no defined mode. '+ es+ PNAME+ '.');	
		END;
	END;


// display options, info, usage, etc.	
PROCEDURE showMessages;
BEGIN
	IF doVersion THEN BEGIN
		Writeln(VERSION);
		HALT;
	END;
	IF doOptions THEN BEGIN
		doBanner;
		showOptions;
		HALT;
	END;
	IF doInfo OR noParams THEN BEGIN
		doBanner;
		showInfo;
		HALT;
	END;
	IF doHelp THEN BEGIN
		doBanner;
		showHelp;
		HALT;
	END;
	IF doChallenge THEN BEGIN
		doBanner;
		showChallenge;
		HALT;
	END;
	IF doWarranty THEN BEGIN
		doBanner;
		showWarranty;
		HALT;
	END;
	IF doConditions THEN BEGIN
		doBanner;
		showConditions;
		HALT;
	END;
	IF doThanks THEN BEGIN
		doBanner;
		showThanks;
		HALT;
	END;
	IF doLegend THEN BEGIN
		doBanner;
		showLegend;
		HALT;
	END;
	IF doMagic THEN BEGIN 
		showMagic; 
		HALT; 
	END;
END;


// fallback License display
PROCEDURE showShortLicense;
	VAR i : INTEGER;
	BEGIN
		FOR i := 1 TO 4 DO BEGIN
			PrintLn(LICENSE[i]);
			Writeln;
		END;
	END;
	
	
PROCEDURE showHelp;
	BEGIN
		showOptions;
	END;


// inline Terms & Conditions
// invoked with [-w] and [-W]
PROCEDURE showWarranty;
	BEGIN
	{$ifdef distrib}
		IF NOT More('disclaimer.txt',10) THEN showShortLicense;
	{$else}
		{$ifdef cli}
			Writeln(' [ Not a distributable build ] ');
		{$endif}
	{$endif}
	END;

	
PROCEDURE showConditions;
	BEGIN
	{$ifdef distrib}
		IF NOT More('conditions.txt',10) THEN showShortLicense;
	{$else}
		{$ifdef cli}
			Writeln(' [ Not a distributable build ] ');
		{$endif}
	{$endif}
	END;

	
// The Key to SES, life, the Universe, and everything
PROCEDURE showMagic;
	BEGIN
		Writeln(MAGIC);
	END;


END.
